'use strict';

module.exports = function createUpdatedCollection(collectionA, objectB) {
  let arr = [];
  for(let i of collectionA){
    let a = Object.keys(i);
    if(minerstheSame(objectB,i.key)){
        i.count=i.count-parseInt(i.count/3);
    }
    arr.push({
      key: i.key,
      count: i.count
    })
  }
 
  return arr; 
}

function minerstheSame(obj,i){
  for (let a in obj){
    for(let item of obj[a]){
      if(item == i){
        return true;
      }
    }
  }
  return false;
}

